﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;
using System.Collections;//请先添加引用
namespace DBEmr.DAL
{
	/// <summary>
	/// 数据访问类METIER。
	/// </summary>
	public class METIER
	{
        DbHelperOra sql_help;
		public METIER()
		{
			sql_help = new DbHelperOra();
		}
		#region  成员方法


		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string M_ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from METIER");
			strSql.Append(" where M_ID='"+M_ID+"' ");
			return sql_help.Exists(strSql.ToString());
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(DBEmr.Model.METIER model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into METIER(");
			strSql.Append("M_ID,M_NAME,M_PYM");
			strSql.Append(")");
			strSql.Append(" values (");
			strSql.Append("'"+model.M_ID+"',");
			strSql.Append("'"+model.M_NAME+"',");
			strSql.Append("'"+model.M_PYM+"'");
			strSql.Append(")");
			sql_help.ExecuteSql(strSql.ToString());
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public void Update(DBEmr.Model.METIER model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update METIER set ");
			strSql.Append("M_NAME='"+model.M_NAME+"',");
			strSql.Append("M_PYM='"+model.M_PYM+"'");
			strSql.Append(" where M_ID='"+ model.M_ID+"' ");
			sql_help.ExecuteSql(strSql.ToString());
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public void Delete(string M_ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete METIER ");
			strSql.Append(" where M_ID='"+M_ID+"' " );
			sql_help.ExecuteSql(strSql.ToString());
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public DBEmr.Model.METIER GetModel(string M_ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select M_ID,M_NAME,M_PYM ");
			strSql.Append(" from METIER ");
			strSql.Append(" where M_ID='"+M_ID+"' " );
			DBEmr.Model.METIER model=new DBEmr.Model.METIER();
			DataSet ds=sql_help.Query(strSql.ToString());
			if(ds.Tables[0].Rows.Count>0)
			{
				model.M_ID=ds.Tables[0].Rows[0]["M_ID"].ToString();
				model.M_NAME=ds.Tables[0].Rows[0]["M_NAME"].ToString();
				model.M_PYM=ds.Tables[0].Rows[0]["M_PYM"].ToString();
				return model;
			}
			else
			{
				return null;
			}
		}
		/// <summary>
		/// 获得数据Dataset列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select M_ID,M_NAME,M_PYM ");
			strSql.Append(" FROM METIER ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return sql_help.Query(strSql.ToString());
		}

        /// <summary>
        /// 获得数据List列表
        /// </summary>
        public ArrayList GetModelList()
        {
            DBEmr.Model.METIER model;
            ArrayList List_model = new ArrayList();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select M_ID,M_NAME,M_PYM ");
            strSql.Append(" FROM METIER ");
            DataSet ds = sql_help.Query(strSql.ToString());
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                model = new DBEmr.Model.METIER();
                model.M_ID = ds.Tables[0].Rows[i]["M_ID"].ToString();
                model.M_NAME = ds.Tables[0].Rows[i]["M_NAME"].ToString();
                model.M_PYM = ds.Tables[0].Rows[i]["M_PYM"].ToString();
                List_model.Add(model);
            }
            return List_model;
        }

		/*
		*/

		#endregion  成员方法
	}
}

